<template>
	<view class="content">
		<view>
			<u-toast ref="uToast" />
		</view>
		<!-- 顶部搜索 -->
		<Search>
			<template #content>
				<!-- 轮播图 -->
				<view class="banner">
					<swiper class="swiper" indicator-dots autoplay interval="3000" indicator-active-color="#63CCFA"
						indicator-color="rgba(99,204,250,.3)">
						<swiper-item class="swiper-item" v-for="item in bannerList" :key="item.bannerUrl"
							@click="detail(item.bannerUrl)">
							<image :src="'http://yihao.cdn.gd-zjgj.com/' + item.bannerImage" lazy-load></image>
						</swiper-item>
					</swiper>
				</view>
			</template>
		</Search>
		<!-- 动态图片 -->
		<GifPic></GifPic>

		<!-- 菜单栏 -->
		<view class="nav-list">
			<!-- 活动专区 -->
			<view class="nav-item" @click="specialarea(13, 1)">
				<image src="../../static/icon/v1/index_huodong.png" mode="widthFix"></image>
			</view>
			<!-- 特供专区 -->
			<view class="nav-item" @click="specialarea(16, 1)">
				<image src="../../static/icon/v1/index_teggong.png" mode="widthFix"></image>
			</view>
			<!-- 交易全区 -->
			<view class="nav-item" @click="transaction">
				<image src="../../static/icon/v1/index_jiaoyi.png" mode="widthFix"></image>
			</view>
			<!-- 兑换专区 -->
			<view class="nav-item" @click="exchange">
				<image src="../../static/icon/v1/index_fudou.png" mode="widthFix"></image>
			</view>
			<!-- 积分专区 -->
			<view class="nav-item" @click="specialarea('', 3)">
				<image src="../../static/icon/v1/index_jifen.png" mode="widthFix"></image>
			</view>
			<!-- 生活服务 -->
			<view class="nav-item" @click="show('敬请期待~', 'default' )">
				<image src="../../static/icon/v1/index_shenghuo.png" mode="widthFix"></image>
			</view>
			<!-- 直播专区 -->
			<view class="nav-item" @click="show('敬请期待~', 'default' )">
				<image src="../../static/icon/v1/index_zhibo.png" mode="widthFix"></image>
			</view>
			<!-- 生态专区 -->
			<view class="nav-item" @click="show('敬请期待~', 'default' )">
				<image src="../../static/icon/v1/index_shengtai.png" mode="widthFix"></image>
			</view>
			<!-- 公益 -->
			<view class="nav-item" @click="show('敬请期待~', 'default' )">
				<image src="../../static/icon/v1/index_gongyi.png" mode="widthFix"></image>
			</view>
		</view>
		<!-- 提示 -->
		<Notice></Notice>

		<!-- 图片 -->
		<view class="pic">
			<image src="../../static/icon/v1/app_new.png" mode="widthFix"></image>
		</view>
		<!-- 商品列表 -->
		<ProList></ProList>
	</view>
</template>

<script>
	import request from '@/util/request.js'
	import Search from '@/components/index/Search/Search.vue'
	import GifPic from '@/components/index/GifPic/GifPic.vue'
	import Notice from '@/components/index/Notice/Notice.vue'
	import ProList from '@/components/index/ProductList/ProductList.vue'
	export default {
		data() {
			return {
				bannerList: [],
				loadMore: false,
				page: 1
			}
		},
		components: {
			GifPic,
			Search,
			Notice,
			ProList
		},
		onLoad() {
			this.requestBannerList()
		},
		methods: {
			// 请求轮播图数据
			requestBannerList() {
				request.globalRequest({
					url: '/api/public/banner_list',
					data: {
						position: 'home'
					}
				}).then(res => {
					this.bannerList = res
				})
			},
			// 前往商品详情页面
			detail(uuid) {
				console.log(uuid.slice(9));
				uni.navigateTo({
					url: "/pages/productdetail/productdetail?uuid=" + uuid.slice(9)
				})
			},
			show(title, type, position, callback) {
				this.$refs.uToast.show({
					title,
					type,
					duration: 1000,
					position: position || "center",
					callback: callback ? callback : () => {}
				})
			},
			specialarea(typeid, malltype) {
				uni.navigateTo({
					url: `/pages/specialarea/specialarea?typeid=${typeid}&malltype=${malltype}`
				})
			},
			transaction() {
				uni.navigateTo({
					url: "/pages/transaction/transaction"
				})
			},
			exchange() {
				uni.navigateTo({
					url: '/pages/exchange/exchange'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #F1F1F1;
		padding: 0 10rpx;

		.banner {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			padding: 0 10rpx;
			text-align: center;

			.swiper {
				height: calc(710rpx * 980 / 2000);

				.swiper-item {
					border-radius: 40rpx;
					overflow: hidden;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

		}

		.nav-list {
			margin-top: 30rpx;
			display: flex;
			flex-wrap: wrap;
			padding: 0 10rpx;
			justify-content: space-between;

			.nav-item {
				width: 32%;
				margin-bottom: 10rpx;

				image {
					width: 100%;
				}
			}
		}

		.pic {
			margin-top: 30rpx;

			image {
				width: 100%;
			}
		}
	}
</style>
